<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>32.使用原型工厂封装继承</title>
</head>

<body>
</body>

<script>
  //原型工厂是将继承的过程封装，使用继承业务简单化。
  function extend (sub, sup) {
    sub.prototype = Object.create(sup.prototype);
    sub.prototype.constructor = sub;
    
    Object.defineProperty(sub.prototype, "constructor", {
      value: sub,
      enumerable: false //禁止遍历
    });
  }
  function User (name, age) {
    this.name = name;
    this.age = age;
  }
  User.prototype.show = function () {
    console.log(this.name, this.age);
  }
  function Admin (...arg) {
    User.apply(this, arg);
  }

  function Member (...arg) {
    User.apply(this, arg);
  }


  extend(Admin, User); //Admin继承User
  extend(Member, User); //Member继承User

 
  let admin = new Admin('zx',18);
  admin.show();//zx 18

  let member = new Member('zm',19);
  member.show();//zm 19
</script>

</html>